<?php
require ('template/header.php');
?>

<div class="index-content">
    <div class="left-content1">
        <h3>Danh mục sản phẩm</h3>
        <div>
            <ul class="danhmuc">
                <?php
                foreach ($c as $key => $value) {
                    ?>
                    <li class="danhmuc0"><a href="index.php?id=<?php echo $value['cat_id']; ?>"><?php echo $value['name']; ?></a>
                        <?php
                        $i = $value['cat_id'];
                        $s = $cat->getSubCategories($i);
                        ?>
                        <ul class="danhmuc1">
                            <?php
                            foreach ($s as $key1 => $value1) {
                                ?>
                                <li><a href="index.php?id=<?php echo $value1['cat_id']; ?>"><?php echo $value1['name']; ?></a></li>
                                <?php
                            }
                            ?>                            
                        </ul>
                    </li>

                    <?php
                }
                ?>
            </ul>
        </div>

        <div></div>
        <div></div>
    </div> <!--end left-content1-->
    <?php
    if (isset($_REQUEST['txtSearch'])) {
        if (!isset($_REQUEST['page'])) {
            $_REQUEST['page'] = 1;
        }
        $p = $_REQUEST['page'];
        $v = ($p - 1) * 6;
        $s = $_REQUEST['txtSearch'];       
        require './db.php';
        require './admin/search.php';
        
        
        $se = new search();
        $ser = $se->db->escape($s);
        $rows = $se->getProducts($ser,$v);
        
        
        $n = getRecordsSearch($ser);
        $tong_so_trang = ceil($n / 6);
        ?>
        <div class="main-content1">
            <div class="tieude1">
                <div class="tieude11">
                    <h2>Tìm kiếm</h2>
                    <em>hiển thị 6 kết quả</em>
                </div>
                <div class="locketqua1" >
                    <select name="loctheogia">
                        <option>Lọc theo giá</option>
                        <option value="">Từ thấp đến cao</option>
                        <option value="">Từ cao đến thấp</option>
                    </select>
                </div>          
            </div> <!--end tieude1-->

            <div class="noidung1">
                <?php
                foreach ($rows as $key => $value) {
                    ?>
                    <div class="sanpham1">
                        <div class="img1"><a href="detail.php?id=<?php echo $value['pro_id']; ?>">
                                <img src="<?php echo $value['image']; ?>"/>
                            </a></div>
                        <a href="detail.php?id=<?php echo $value['pro_id']; ?>"><?php echo $value['name']; ?></a>
                        <div class="gia1"><?php echo number_format($value['price']); ?>đ</div>
                    </div>
                    <?php
                }
                ?>
            </div>
            <div class="paging">
                <?php
                if ($p > 1) {
                    echo "<a href='search.php?txtSearch=$s&page=" . ($p - 1) . "'>pre</a>";
                }
                for ($i = 1; $i <= $tong_so_trang; $i++) {
                    echo "<a href ='search.php?txtSearch=$s&page=$i'>" . $i . "</a>";
                }
                if ($p < $tong_so_trang) {
                    echo "<a href='search.php?txtSearch=$s&page=" . ($p + 1) . "'>next</a>";
                }
                ?>
            </div>
        </div> <!--end main-content1-->
        <?php
    }
    ?>
</div>
<div class="clear-both"></div>
<?php
require ('template/footer.php');
?>